from django.db import models

# Create your models here.

# 模型的字段类型和约束
class UserModel(models.Model):
    # uid成为主键,原来的id不会创建
    uid = models.AutoField(auto_created=True, primary_key=True)
    # CharField:字符串类型,唯一,索引
    name = models.CharField(max_length=30, unique=True, db_index=True)
    # IntegerField:整型 ,default 默认值
    age = models.IntegerField(default=18)
    # BooleanField:布尔类型
    sex = models.BooleanField(default=True)
    # TextField:文本类型,null 允许为空,blank 在admin管理页面可以为空
    info = models.TextField(null=True, blank=True, default="这个人很懒,什么也没有留下!")
    # FloatField:浮点类型
    salary = models.FloatField(default=5000.00)
    # DecimalField:十进制类型
    #       max_digits:最大位数,decimal_places:小数点位数
    money = models.DecimalField(max_digits=10, decimal_places=2, default=0)

    birthday = models.DateField(null=True, blank=True, default="2012-08-08")

    updatetime = models.DateTimeField(auto_now=True)
    createdatetime = models.DateTimeField(auto_now_add=True)
    birthday4 = models.TimeField(null=True, blank=True, default="12:00:00")
    birthday5 = models.TimeField(auto_now=True)
    files = models.FileField(null=True, upload_to="static/files")
    images = models.ImageField(null=True, upload_to="static/images")

    # 其他约束
    chooice = ((1, "青铜"), (2, "钻石"), (3, "王者"))

    usertype1 = models.IntegerField(
        choices=chooice, default=1, name="usertype1", verbose_name="用户类型1"
    )

    usertype2 = models.IntegerField(
        default=1,
        db_column="usertype2",
        verbose_name="用户类型2",
        editable=False,
    )

# 增删改查
class PersonModel(models.Model):
    name = models.CharField(max_length=30, null=True,default='',unique=True)
    age = models.IntegerField(default=18)

    class Meta:
        db_table = 'tb_person'




